//
//  AddBirthHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/17.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "AddBirthHeaderView.h"

@implementation AddBirthHeaderView

//h：  120
#pragma mark - 1.init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        
        self.backgroundColor = kMainLightGrayColor;
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.div1];
    [self.div1 addSubview:self.nameLb];
    [self.div1 addSubview:self.pleaseInputNameTF];
    
    
    [self addSubview:self.div2];
    [self.div2 addSubview:self.birthDayLb];
    [self.div2 addSubview:self.pleaseBirthDayLb];
    [self.div2 addSubview:self.arrowIv];
}


#pragma mark - 3.layout

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //60
    [self.div1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.mas_top).offset(10);
        make.height.mas_equalTo(50);
    }];
    
    [self.div2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.div1.mas_bottom).offset(1);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(58);
    }];
    
    [self layoutOutDiv1];
    
    [self layoutDiv2];
}

- (void)layoutOutDiv1 {
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div1.mas_left).offset(15);
        make.centerY.equalTo(self.div1.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.pleaseInputNameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(150, 30));
        make.centerY.equalTo(self.div1.mas_centerY);
        make.right.equalTo(self.div1.mas_right).offset(-10);
    }];
}

- (void)layoutDiv2 {
    [self.birthDayLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(15);
        make.centerY.equalTo(self.div2.mas_centerY);
        
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(60); //宽度自适应,国际化显示不全
     }];
    
    [self.pleaseBirthDayLb mas_makeConstraints:^(MASConstraintMaker *make) {
        //150 - 10-15
//        make.size.mas_equalTo(CGSizeMake(125, 30));
        make.height.mas_equalTo(30);
        make.width.mas_greaterThanOrEqualTo(125); //防止国际化后显示不全
        
        
        make.centerY.equalTo(self.div2.mas_centerY);
        make.right.equalTo(self.arrowIv.mas_left);
    }];
    
    
    [self.arrowIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.right.equalTo(self.div2.mas_right).offset(-10);
        make.centerY.equalTo(self.div2.mas_centerY);
    }];
}

#pragma mark - 2.getter
- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
        _div1.backgroundColor = [UIColor whiteColor];
    }
    return _div1;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.text = NSLocalizedString(Name, @"姓名");
    }
    return _nameLb;
}

- (UITextField *)pleaseInputNameTF {
    if(!_pleaseInputNameTF) {
        _pleaseInputNameTF = [[UITextField alloc] init];
        
        _pleaseInputNameTF.placeholder = NSLocalizedString(ToastPleaseInputName,@"请输入姓名");
        
        _pleaseInputNameTF.textAlignment = NSTextAlignmentRight;
    }
    return _pleaseInputNameTF;
}



////
- (UIView *)div2 {
    if (!_div2) {
        _div2 = [UIView new];
        _div2.backgroundColor = [UIColor whiteColor];
        
        //添加手势
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] init];
        [tapGes addTarget:self action:@selector(clickBirthDayAction)];
        [_div2 addGestureRecognizer:tapGes];
    }
    return _div2;
}
//!!!!: 选择日期点击事件回调
- (void)clickBirthDayAction {
    
    if (self.headerViewSelectBirthDayBlock) {
        self.headerViewSelectBirthDayBlock();
    }
}

- (UILabel *)birthDayLb {
    if (!_birthDayLb) {
        _birthDayLb = [UILabel new];
        _birthDayLb.text = NSLocalizedString(Birthday, @"生日");
    }
    return _birthDayLb;
}
- (UILabel *)pleaseBirthDayLb {
    if (!_pleaseBirthDayLb) {
        _pleaseBirthDayLb = [UILabel new];
        _pleaseBirthDayLb.text = NSLocalizedString(ToastPleaseSelectDate, @"请选择日期");

        _pleaseBirthDayLb.textColor = [UIColor lightGrayColor];
        _pleaseBirthDayLb.textAlignment = NSTextAlignmentRight;
    }
    return _pleaseBirthDayLb;
}
- (UIImageView *)arrowIv {
    if (!_arrowIv) {
        _arrowIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"右箭头.png"]];
    }
    return _arrowIv;
}

@end
